home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
quintus
/
quintus0.lha
/
work
/
try_2.06.2
< prev
next >
Wrap
Text File
|
1992-04-03
|
20KB
|
760 lines
%%% TRY
%%% version 2.00.1 (based on try_19.1)
%%% added equality rewriting
%%% version 2.01.0
%%% rewrote clauses in all round 0s instead of just session 1 round 0
%%% version 2.01.5
%%% added code to rewrite asserted clauses
%%% version 2.01.8
%%% added transformed form of all non-input equations before hyper-linking
%%% version 2.02.2
%%% asserted pulled out equations at beginning of session
%%% version 2.02.5
%%% asserted pulled out forms of equations at the beginning of each round
%%% version 2.03.0
%%% asserted equations for rewrite rules during round 0 (except for session
%%% 1 round 0) in addtion to other rounds
%%% version 2.03.4
%%% incorporated changes made to clin V1 between 7/31/90 and 10/18/90 which
%%% are visible externally -- changes to comments, predicate names, and
%%% variable names are not incorporated
%%% version 2.03.5
%%% assert equations for rewrite rules only if there are rewrite rules
%%% version 2.03.8
%%% don't rewrite clauses if proof found durin hyper-linking
%%% rewrite clauses in round 0 when necessary
%%% version 2.04.0
%%% saved input clauses between sessions same as clin 1
%%% version 2.04.1
%%% determined maximum number of non-ground literals in a clause each round
%%% (required for equality transform)
%%% version 2.04.3
%%% rewrote clauses after replacement (as well as before)
%%% version 2.04.4
%%% no longer pull out equations at the beginning of rounds
%%% when replacing and rewriting, perform replacement/rewrite repeatedly
%%% until no change
%%% version 2.04.5
%%% added equality_transform_by_round flag
%%% version 2.04.6
%%% added fixed_priority
%%% fixed bug in code which determines if another round of hyper-linking is
%%% required
%%% version 2.04.7
%%% rewrote asserted clauses after unit simplification
%%% version 2.04.8
%%% added group_detection
%%% version 2.05.0
%%% don't select a support strategy unless there is a new clause or an
%%% existing clause has modified the appropriate support
%%% version 2.05.2
%%% modified the top level structure of clin
%%% version 2.05.3
%%% added support for Quintus Prolog
%%% fixed bug which caused loop when proof found in simplification
%%% modified clin structure so that clause rewriting done before main
%%% repeat loop and after simplification
%%% version 2.05.5
%%% modified clin structure so generation of equations from rewrite rules
%%% done before main repeat loop after clause rewriting
%%% fixed bug which prevented "satisfiable" result
%%% version 2.05.6
%%% modified round 0 action
%%% don't repeat clause generation unless more than 1 clause generation
%%% modules requested
%%% moved instance deletion into clause generation loop
%%% added print after clause generation
%%% version 2.05.7
%%% terminated clause generation loop if proof found in replacemet
%%% version 2.05.8
%%% added priority_bound_increment
%%% version 2.06.0
%%% apply once_replace_rules only once per round
%%% added clause_generation_loop flag
%%% added early check for unit conflict
%%% modified session 1 round 0 processing
%%% added save_rewrite_rules
%%% version 2.06.1
%%% added early unit conflict check to rewrite_rewrite_rules
%%% version 2.06.2
%%% run clause generation loop in session 1 round 0
%%% added additional time overflow tests
%%%
%%% A round consists of the follow:
%%%
%%% if round 0, not session 1, no rewrite rules, not group_dectection, and
%%% not equality_transform_by_round, do nothing
%%% else
%%% if not round 0, then
%%% hyper-link
%%% rewrite clauses
%%% endif
%%% generate equations from rewrite rules
%%% repeat
%%% run group detection
%%% pullout equations
%%% do replacements
%%% run simplification
%%% rewrite clauses
%%% generate equations from rewrite rules
%%% do instance deletion
%%% until no new clauses generated
%%% run PC prover
%%% run small proof checker
%%% endif
%%%
%%% Note that some of the above steps are controlled via user-specified flags;
%%% not all of the steps may be performed.
%%%
%%% If sliding priority is not specified, hyper-matches are generated
%%% until done.
%%% If sliding priority is specified, we divide the running into sessions.
%%% Each session starts with a work unit bound and infinite priority
%%% bound. If a session fails to find the proof, double the work unit
%%% bound, and start a new session.
%%%
%%% If do_replacement_once is asserted, then we do top level replacements
%%% only at round 0.
%%%
%%% If the problem is tried more than once with same time limit, but
%%% only with different strategies, then we skip round 0.
%%% However, we have to do replacements before call round 1 if
%%% do_replacement_once is asserted.
%%%
%%% clause_largest_length is very important, we use it in small proof
%%% checking and hyper-matching.
%%% If tried_round is 1, this means we are using top level supervisor,
%%% and the problem we are trying has been tried before with
%%% different strategies in same time limit. Since all the calls
%%% in round 0 have been executed before, we don't execute them again.
%%% However, we should run top_level_replace if it is specified.
%%%
%%% The replacement, if set, will be executed at round 0 of each session.
%%%
try :- not(not(try_fail)).
try_fail :-
priority_option,
assert(round_no(-1)), % initial value for round number.
assert(session_no(1)), % initial value for round number.
cputime(Time),
assert(start_time(Time)),
assert(round_time(Time,-1)),
assert(pc_time(0)), % initialize PC time.
nl,
write_line(5,'TRY BEGINS:'),
try_1,
!.
%%% Interative exexution of rounds.
try_1 :-
precheck,
!.
try_1 :-
repeated_clause_generation_needed,
fail.
try_1 :-
repeat,
print_roundheader,
assert_new_support,
round_process,
round_spent_time.
%%% Check to see if repeated clause generation is required.
repeated_clause_generation_needed :-
not(clause_generation_loop),
!,
assert(no_repeated_clause_generation).
repeated_clause_generation_needed :-
repeated_clause_generation_needed_1(0,N1),
repeated_clause_generation_needed_2(N1,N2),
repeated_clause_generation_needed_3(N2,N3),
repeated_clause_generation_needed_4(N3,N4),
repeated_clause_generation_needed_5(N4,N5),
repeated_clause_generation_needed_6(N5,N6),
N6 < 2,
!,
assert(no_repeated_clause_generation),
!.
repeated_clause_generation_needed :-
abolish(no_repeated_clause_generation,0),
!.
repeated_clause_generation_needed_1(N1,N2) :-
group_detection,
!,
N2 is N1 + 1.
repeated_clause_generation_needed_1(N,N).
repeated_clause_generation_needed_2(N1,N2) :-
replacement,
!,
N2 is N1 + 1.
repeated_clause_generation_needed_2(N,N).
repeated_clause_generation_needed_3(N1,N2) :-
equality_transformation_by_round,
!,
N2 is N1 + 1.
repeated_clause_generation_needed_3(N,N).
repeated_clause_generation_needed_4(N1,N2) :-
unit_resolution,
!,
N2 is N1 + 1.
repeated_clause_generation_needed_4(N,N).
repeated_clause_generation_needed_5(N1,N2) :-
auto_orient,
!,
N2 is N1 + 1.
repeated_clause_generation_needed_5(N,N).
repeated_clause_generation_needed_6(N1,N2) :-
rwr(_,_,_,_),
!,
N2 is N1 + 1.
repeated_clause_generation_needed_6(N,N).
%%% Executing one round.
round_process :-
round_no(0),
not(session_no(1)),
not(rwr(_,_,_,_)),
not(group_dection),
not(equality_transform_by_round),
round_spent_time,
!,
fail.
round_process :-
round_no(0),
!,
round_process_1.
round_process :-
check_hm_round,
not(prove_result(_)),
not(time_overflow),
clause_rewriting,
not(prove_result(_)),
not(time_overflow),
!,
round_process_1.
round_process.
round_process_1 :-
clause_generation,
print_after_clause_generation,
round_process_2.
round_process_2 :-
prove_result(_),
!.
round_process_2 :-
time_overflow,
!.
round_process_2 :-
pc_spc,
!.
round_process_2 :-
time_overflow,
!.
round_process_2 :-
not(get_new_supp(_,_)),
hl_complete.
round_process_2 :-
round_spent_time,
!,
fail.
%%% Generate clauses after hyper-linking.
clause_generation :-
rewrite_rule_equations,
abolish(no_replace_once,0),
repeat,
update_oldsentC1,
run_group_detection,
clause_generation_1,
!.
clause_generation_1 :-
prove_result(_),
!.
clause_generation_1 :-
time_overflow,
!.
clause_generation_1 :-
transform_equations_round,
top_level_replace,
assert_once(no_replace_once),
run_simplify,
!.
clause_generation_1 :-
time_overflow,
!.
clause_generation_1 :-
clause_rewriting,
(prove_result(_);time_overflow),
!.
clause_generation_1 :-
rewrite_rule_equations,
not(inst_del),
print_after_instdel,
repeat_clause_generation,
!.
% Fail if we need to repeat clause generation.
repeat_clause_generation :-
no_repeated_clause_generation,
!.
repeat_clause_generation :-
not(diff_sentC1),
!.
run_simplify :-
prove_result('unsatisfiable'), !.
run_simplify :-
simplify, % if an EC derived.
assert_tryresult('unsatisfiable'),
assert_prooftype('US').
run_pcprover :-
compute_fms(FMS), % compute fully matched set.
print_fms(FMS), !,
pcprove(FMS),
assert_tryresult('unsatisfiable'),
assert_prooftype('PC').
run_spc :-
spc,
assert_tryresult('unsatisfiable'),
assert_prooftype('SP').
%%% If the input set has neither positive nor negative clauses,
%%% and no replacements are specified, then it is satisfiable.
precheck :-
check_emptyclause,
assert_tryresult('unsatisfiable'),
assert_prooftype('PR'), !.
precheck :-
check_emptyset,
assert_tryresult('satisfiable'), !.
precheck :-
\+ replacement,
\+ have_pn_clauses,
write_line(5,'No positive or negative clauses !!'),
assert_tryresult('satisfiable'), !.
%%% hm_round can be turned off.
check_hm_round :-
do_hyper_linking,
update_oldsentC,
hm_round,
abolish(saved_supp,2),
print_ahm, !.
check_hm_round :- !.
%%% Check to see if hyper-linking is done.
hl_complete :-
decidably_satisfiable.
hl_complete :-
more_session.
pc_spc :-
check_run_pc.
pc_spc :-
run_spc.
%%% If UR round, no PC prover.
check_run_pc :-
current_support(sup(_,_,_,1)),
!,
fail.
check_run_pc :-
run_pcprover.
%%% If the set is empty.
check_emptyset :-
\+ sent_C(_), !.
%%% If there is an empty clause.
check_emptyclause :-
sent_C(cl(_,_,by([],_,_,_,_),_,_,_,_,_,_)), !.
%%% If having positive and negative clauses.
have_pn_clauses :-
have_p_clauses, !,
have_n_clauses.
%%% If having positive clauses.
have_p_clauses :-
sent_C(cl(_,_,by(Cn1,_,_,_,_),_,_,_,_,_,_)),
posclause(Cn1).
%%% If having negative clauses.
have_n_clauses :-
sent_C(cl(_,_,by(Cn1,_,_,_,_),_,_,_,_,_,_)),
negclause(Cn1).
assert_prooftype(Message) :-
assert(proof_type(Message)).
assert_tryresult(Result) :-
assert(prove_result(Result)).
%%% Information for fixed and sliding priority.
priority_option :-
fixed_priority,
compute_start_priority_bound(P),
assert(priority_bound(P)),
!.
priority_option :-
slidepriority,
compute_start_wu(WU),
assert(priority_bound(WU)),
assert(wu_bound(WU)),
assert(total_numhm(0)),
assert(total_wu(0)), !.
priority_option.
%%% compute the start priority bound.
%%% set by user -- fail.
%%% not set by user -- return maximum priority of input clauses.
compute_start_priority_bound(P) :-
start_priority_bound(P).
compute_start_priority_bound(P) :-
bagof1(D9e,{D1,D2,D3,D4,D5,D6,D7,D8,D9a,D9b,D9c,D9d}^
sent_C(cl(D1,D2,D3,D4,D5,D6,D7,D8,pr(D9a,D9b,D9c,D9d,D9e))),
Ps),
max_list(Ps,P).
simplify :-
print_busentC,
fol_simplify,
print_ausentC, !.
simplify :-
print_ausentC,
!,
fail.
%%% Obtain the largest number of non-ground literals of clauses.
clause_largest_length(N) :-
bagof(NL,{X1,X3,X4,X5,X6,X7,X8,X9}^
sent_C(cl(X1,NL,X3,X4,X5,X6,X7,X8,X9)),NLs),
max_list(NLs,N),
!.
clause_largest_length(0).
%%% Print out header information for a round.
print_roundheader :-
session_no(Y),
inc_roundno(X), % increment round no.
nl, tab(15), write('SESSION '), write(Y),
tab(10), write('ROUND '), write(X), nl,
write_line(5,'#######################################################'),
file_name(File),
write_line(19,'File Name = ',File),
relevance_bound(RelBound),
write_line(17,'Relevance Bound = ',RelBound),
print_priority_figures, !.
%%% Increment round number and assert it.
inc_roundno(Y) :-
retract(round_no(X)), Y is X + 1,
assert(round_no(Y)), !.
%%% Print out information if sliding priority is used.
print_priority_figures :-
fixed_priority,
priority_bound(PrioBound),
write_line(17,'Priority Bound = ',PrioBound), !.
print_priority_figures :-
slidepriority,
wu_bound(WUBound),
write_line(20,'WU Bound = ',WUBound),
priority_bound(PrioBound),
write_line(17,'Priority Bound = ',PrioBound), !.
print_priority_figures.
%%% Print out how much time spent in the past round.
round_spent_time :-
round_no(X), Y is X - 1,
cputime(Time),
retract(round_time(LT,Y)),
Used_Time is Time - LT,
write_line(5,'Time elapsed in this level(s): ',Used_Time),
assert(round_time(Time,X)), !.
%%% We can detect if a problem is really satisfiable.
decidably_satisfiable :-
\+ over_priohm, !,
\+ over_relevance, !,
\+ over_litbound, !,
\+ over_numvars,
assert_tryresult('satisfiable').
%%% Determine is time has overflowed.
time_overflow :-
is_time_overflow,
assert_tryresult('time_overflow').
is_time_overflow :-
start_time(Start_Time),
real_time_limit(Max_Time),
cputime(Current_Time),
Used_Time is Current_Time - Start_Time,
!,
Used_Time > Max_Time.
%%% Check if a new session is needed.
more_session :-
not(fixed_priority),
not(slidepriority),
!,
assert_tryresult('misc_overflow').
more_session :-
check_stopsession.
%%% If there are some hyper-matches deleted due to priority overflow,
%%% do check_maxhmno.
check_stopsession :-
over_priohm, !,
check_stopsession_1.
%%% Otherwise, stop.
check_stopsession :-
assert_tryresult('misc_overflow').
check_stopsession_1 :-
fixed_priority,
!,
round_spent_time,
retract(priority_bound(P)),
priority_bound_increment(I),
P1 is P+I,
assert(priority_bound(P1)),
!,
new_session.
check_stopsession_1 :-
slidepriority,
!,
check_maxhmno.
%%% Check if the number of clauses in the database exceeds a specified
%%% number.
check_maxhmno :-
total_numhm(NumHm),
wu_bound(WU),
priority_bound(P),
max_no_clauses(MaxHMNo), !,
check_maxhmno_1(NumHm,MaxHMNo,WU).
%%% If the number of clauses in the database does not exceed a specified
%%% number.
check_maxhmno_1(NumHm,MaxHMNo,WU) :-
NumHm =< MaxHMNo, !,
round_spent_time,
Temp is 2.0 * WU,
floor(Temp,Y),
not(not(abolish(wu_bound,1))),
assert(wu_bound(Y)),
!, new_session.
%%% If the number of clauses in the database exceeds a specified
%%% number, stop.
check_maxhmno_1(_,_,_) :-
assert_tryresult('clause_no_overflow').
%%% Start a new session.
new_session :-
not(not(session_deletions)),
not(not(setup_inputs)),
session_asserts,
!, fail.
%%% Assert some initial values for a new session.
session_asserts :-
cputime(Time),
assert(round_time(Time,-1)),
assert(round_no(-1)),
inc_session,
wu_bound(S),
abolish(priority_bound,1),
assert(priority_bound(S)),
assert(total_wu(0)),
assert(total_numhm(0)).
%%% Increase session number.
inc_session :-
retract(session_no(X)),
Y is X + 1,
assert(session_no(Y)).
%%% Use the input clauses stored at the beginning.
setup_inputs :-
slidepriority,
retract(sent_C(cl(_,_,_,0,_,_,_,_,_))),
fail.
setup_inputs :-
not(save_rewrite_rules),
!,
abolish(rwr,4),
(outrwr -> (
abolish(outrwr,0),
setup_inputs_1,
assert(outrwr)
); setup_inputs_1).
setup_inputs.
setup_inputs_1 :-
sent_C(cl(_,_,by([S=T],V,V,_,_),_,_,_,_,_,_)),
generate_rewrite_rule([S=T],_),
fail.
setup_inputs_1.
%%% Succeeds if a clause is not generated before.
diff_sentC1 :-
const_list(V),
sent_C(cl(_,_,by(Cn1,V11,V11,V,_),_,_,_,_,_,_)),
not(oldsentC1(Cn1)),
!.
diff_sentC1 :- fail.
%%% Update old clauses.
update_oldsentC :-
const_list(V),
current_support(Supp),
sent_C(cl(_,_,by(Cn1,V11,V11,V,_),_,Sp,_,_,_,_)),
assert_once(oldsentC(Supp,Cn1,Sp)),
fail.
update_oldsentC.
%%% Update old clauses.
update_oldsentC1 :-
not(no_repeated_clause_generation),
const_list(V),
sent_C(cl(_,_,by(Cn1,V11,V11,V,_),_,_,_,_,_,_)),
assert_once(oldsentC1(Cn1)),
fail.
update_oldsentC1.
%%% Assert support strategy for next round.
assert_new_support :-
round_no(0), !.
assert_new_support :-
get_new_supp(Supp_int,Supp),
abolish(current_support,1),
assert(current_support(Supp_int)),
write_line(5,'Support strategy: ',Supp),
!.
%%% Determine support strategy for next round. Fail if hyper_linking is
%%% complete.
get_new_supp(Supp_int,Supp) :-
saved_supp(Supp_int,Supp),
!.
get_new_supp(Supp_int,Supp) :-
retract(num_supp(N1)),
!,
N2 is N1 + 1,
get_new_supp_1(N2,N3),
get_new_supp_2(N1,N3,Supp_int,Supp,N4),
assert(num_supp(N4)),
assert(saved_supp(Supp_int,Supp)),
!.
get_new_supp(Supp_int,Supp) :-
support_list(S),
length(S,N1),
get_new_supp_2(N1,1,Supp_int,Supp,N2),
assert(num_supp(N2)),
assert(saved_supp(Supp_int,Supp)),
!.
get_new_supp_1(N1,1) :-
support_list(Supp),
length(Supp,N2),
N1 > N2,
!.
get_new_supp_1(N,N).
get_new_supp_2(N1,N2,Supp_int,Supp,N2) :-
support_list_internal(Supp_list_int),
get_list(Supp_list_int,N2,Supp_int),
get_new_supp_3(Supp_int),
support_list(Supp_list),
get_list(Supp_list,N2,Supp),
!.
get_new_supp_2(N,N,_,_,_) :-
!,
fail.
get_new_supp_2(N1,N2,Supp_int,Supp,N3) :-
N4 is N2 + 1,
get_new_supp_1(N4,N5),
!,
get_new_supp_2(N1,N5,Supp_int,Supp,N3).
get_new_supp_3(sup(_,_,_,1)) :-
const_list(Clist),
sent_C(cl(_,_,by(Cn1,V11,V11,Clist,_),_,_,_,_,_,_)),
not(oldsentC(Supp_int,Cn1,_)),
!.
get_new_supp_3(sup(Sa,Sb,Sc,0)) :-
const_list(Clist),
sent_C(cl(_,_,by(Cn1,V11,V11,Clist,_),_,sp(S1a,S1b,S1c),_,_,_,_)),
get_new_supp_4([Sa,Sb,Sc],[S1a,S1b,S1c],[S2a,S2b,S2c]),
not(oldsentC(Supp_int,Cn1,sp(S2a,S2b,S2c))),
!.
get_new_supp_4([],[],[]).
get_new_supp_4([0|Ss1],[_|Ss2],[_|Ss3]) :-
!,
get_new_supp_4(Ss1,Ss2,Ss3).
get_new_supp_4([1|Ss1],[S|Ss2],[S|Ss3]) :-
!,
get_new_supp_4(Ss1,Ss2,Ss3).
%%% Compute starting work unit bound.
%%% If the starting work unit bound is specified by the user, done.
compute_start_wu(WU) :-
start_wu_bound(WU), WU \== 0, !.
%%% Otherwise, compute it.
compute_start_wu(WU) :-
compute_start_wu_1(Size,Depth,Literal),
size_coef(C1),
depth_coef(C2),
literal_coef(C3),
relevance_coef(C4),
get_start_no_clauses(ST),
T1 is Size*C1,
floor(T1,KK1),
T2 is Depth*C2,
floor(T2,KK2),
T3 is Literal*C3,
floor(T3,KK3),
T4 is 4*C4,
floor(T4,KK4),
maximum(KK1,KK2,Temp1),
maximum(Temp1,KK3,Temp2),
maximum(Temp2,KK4,Temp3),
WU is ST * Temp3.
compute_start_wu_1(Size,Depth,Literal) :-
bagof1(R,C^clause(sent_C(C),true,R),Rs),
compute_start_wu_1(Rs,Size,Depth,Literal).
compute_start_wu_1([R|Rs],SO,DO,LO) :-
clause(sent_C(cl(_,_,by(Cn,_,_,_,_),_,_,_,_,_,_)),true,R),
max_clausesize_sp(Cn,S1),
clause_depth(Cn,D1),
length(Cn,L1),
compute_start_wu_2(Rs,S1,D1,L1,SO,DO,LO).
compute_start_wu_2([R|Rs],S1,D1,L1,SO,DO,LO) :-
clause(sent_C(cl(_,_,by(Cn,_,_,_,_),_,_,_,_,_,_)),true,R),
max_clausesize_sp(Cn,SM1),
clause_depth(Cn,DM1),
length(Cn,LM),
maximum(S1,SM1,SN2),
maximum(D1,DM1,DN2),
maximum(L1,LM,LN2),
!,
compute_start_wu_2(Rs,SN2,DN2,LN2,SO,DO,LO).
compute_start_wu_2([],SO,DO,LO,SO,DO,LO).
get_start_no_clauses(ST) :-
start_no_clauses(ST), !.
get_start_no_clauses(ST) :-
start_no_clauses_ceof(X),
!,
number_inclauses(IN),
ST is X * IN, !.
get_start_no_clauses(ST) :-
number_inclauses(IN),
ST is 3 * IN.